package day7;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Vector;

/**
 * @author oldliu
 * @since 1.0
 */
public class ClsTest2 {
    public static void main(String[] args) throws Exception {
        Class<Vector> vectorClass = Vector.class;
        Vector vector = vectorClass.newInstance();
        vector.add("ssss");
        System.out.println(vector);
        Class<Student> c = Student.class;//c就是描述Student这个类的
//        Student s=c.newInstance();//无参构造必须有
       // System.out.println(s);
        //调用构造方法
        Constructor<Student> declaredConstructor = c.getDeclaredConstructor(String.class, String.class, String.class,int.class);
        declaredConstructor.setAccessible(true);//允许访问私有方法
        Student s2 = declaredConstructor.newInstance("王乐第", "1939893", "134444", 22);
        System.out.println(s2);
        Field qq = c.getDeclaredField("qq");
        qq.setAccessible(true);

        System.out.println(qq.get(s2));

        qq.set(s2,"155555555");
        System.out.println("修改属性后:"+s2);
        System.out.println(">>>>>>>>>>>>>>>>>>");
        Method m=c.getDeclaredMethod("changeAge",int.class);
        m.setAccessible(true);
        Object rtn = m.invoke(s2, 24);//调用s2.changeAge方法
        System.out.println("方法返回值："+rtn);
        System.out.println(s2);

    }
}
